package com.mine.modules.vm.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mine.modules.vm.entity.VmAssets;
import com.mine.modules.vm.entity.VmMonitor;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 监控设备 Mapper 接口
 * </p>
 *
 * @author xujf
 * @since 2024-09-22
 */
public interface VmMonitorMapper extends BaseMapper<VmMonitor> {

    @Select({
            "<script>",
            "SELECT b.*, a.scene_layer_id AS element_scene_layer_id, a.id AS sid ",
            "FROM vm_layer_element a ",
            "LEFT JOIN vm_monitor b ON a.element_id = b.id ",
            "WHERE a.element_type='video_monitor' AND a.layer_id IN ",
            "   <foreach collection='layerIdList' item='id' open='(' separator=',' close=')'>",
            "       #{id}",
            "   </foreach>",
            "   <if test='keyword != null and keyword != \"\"'>",
            "       AND (b.camera_name LIKE CONCAT('%', #{keyword}, '%') or b.camera_index_code LIKE CONCAT('%', #{keyword}, '%') ) ",
            "   </if>",
            "   <if test='treeIndexCode != null and treeIndexCode != \"\"'>",
            "       AND b.region_index_code = #{treeIndexCode} ",
            "   </if>",
            "</script>"
    })
    IPage<VmMonitor> selectPageWithElement(
            Page<?> page,
            @Param("layerIdList") List<String> layerIdList,
            @Param("keyword") String keyword,
            @Param("treeIndexCode") String treeIndexCode
    );

}
